<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编程式导航</title>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
    <style>

    </style>
</head>

<body>
    <div id="app">
        <h1>Hello App!</h1>
           
        <router-link to="/user" @click="naviByQuery">查询参数</router-link>
        <router-view></router-view>
    </div>
</body>
<script>

    const User = {
        template: `
        <div>
            <div>用户</div>
        </div>    
        ` 
    };

    const UserDetail = {
        template:`
        <div>
            <p>用户详情</p>
        </div>
        `
    }


    const routes = [
        {
            path: '/user',
            component: User,
        },
        {
            path:"/user-detail/:id",
            component:UserDetail,
            name:'detail'
        }
    ]

    // 3. 创建 router 实例，然后传 `routes` 配置
    const router = new VueRouter({
        routes // (缩写) 相当于 routes: routes
    })

    // 4. 创建和挂载根实例。
    // 记得要通过 router 配置参数注入路由，
    // 从而让整个应用都有路由功能
    const app = new Vue({
        router,
        methods: {
            naviByQuery(){
                console.log(123);
                this.$router.push({
                    // path:"user",
                    name:"detail",
                    query:{
                        id:456,
                        name:"小明"
                    }
                });
            }

        },
    }).$mount('#app')

// 现在，应用已经启动了！
</script>

</html>